package com.twsjw.action;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.twsjw.dao.houseDAOImpl;
import com.twsjw.dao.userDAOImpl;
import com.twsjw.entity.Houseinfo;

public class houseAction {
	private String houseid;
	
	public String title;
	public String district_id;
	public String street_id;
	public String room;
	public String hall;
	public String floor;
	public String area;
	public String house_age;
	public String price;
	public String telephone;
	public String contract_man;
	public String remark;
	

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getDistrict_id() {
		return district_id;
	}

	public void setDistrict_id(String district_id) {
		this.district_id = district_id;
	}

	public String getStreet_id() {
		return street_id;
	}

	public void setStreet_id(String street_id) {
		this.street_id = street_id;
	}

	public String getRoom() {
		return room;
	}

	public void setRoom(String room) {
		this.room = room;
	}

	public String getHall() {
		return hall;
	}

	public void setHall(String hall) {
		this.hall = hall;
	}

	public String getFloor() {
		return floor;
	}

	public void setFloor(String floor) {
		this.floor = floor;
	}

	public String getArea() {
		return area;
	}

	public void setArea(String area) {
		this.area = area;
	}


	public String getHouse_age() {
		return house_age;
	}

	public void setHouse_age(String house_age) {
		this.house_age = house_age;
	}

	public String getPrice() {
		return price;
	}

	public void setPrice(String price) {
		this.price = price;
	}

	public String getTelephone() {
		return telephone;
	}

	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}

	public String getContract_man() {
		return contract_man;
	}

	public void setContract_man(String contract_man) {
		this.contract_man = contract_man;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public String getHouseid() {
		return houseid;
	}

	public void setHouseid(String houseid) {
		this.houseid = houseid;
	}

	public String select()
	{	
		ActionContext act=ActionContext.getContext();
		Map session=act.getSession();
		String userid=session.get("userid").toString();
		//��ѯ��ݿ�
		houseDAOImpl cus=new houseDAOImpl();
		List l=cus.select(userid);
		act.put("sele",l);
		
		return "success";
		
	}
	
	public String dele(){
		houseDAOImpl h=new houseDAOImpl();
		h.delinfo(houseid);
		return "success";
	}
	
	public String insert(){
		SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String date=format.format(new Date());
		Timestamp ts=Timestamp.valueOf(date);
		ActionContext act=ActionContext.getContext();
		Map session=act.getSession();
		String userid=session.get("userid").toString();
		
		Houseinfo h=new Houseinfo(new Integer(room),new Integer(hall),remark,new Double(price),
				title,ts,telephone,contract_man,new Double(area),new Integer(floor),new Integer(house_age));
		
		houseDAOImpl hou=new houseDAOImpl();
		hou.insert(h,district_id,street_id,userid);
		return "success";
	}
	public String selinfo()
	{
		houseDAOImpl hd=new houseDAOImpl();
		Houseinfo hinfo= hd.selhouse(houseid);
		ActionContext act=ActionContext.getContext();
		act.put("hinfo", hinfo);
		return "success";
	}
	
	public String update(){
		SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String date=format.format(new Date());
		Timestamp ts=Timestamp.valueOf(date);
		Houseinfo h=new Houseinfo(new Integer(room),new Integer(hall),remark,new Double(price),title,ts,telephone,contract_man,
				new Double(area),new Integer(floor),new Integer(house_age));
		
		houseDAOImpl hou=new houseDAOImpl();
		hou.updateinfo(h,district_id,street_id,houseid,ts);
		return "success";	
	}
}
